﻿using System;
using System.Web.Mvc;
using Castle.Windsor;

namespace MvcStarterKit.UI.Helpers
{
	public class WindsorControllerFactory : DefaultControllerFactory
	{
		private readonly IWindsorContainer _container;

		public WindsorControllerFactory(IWindsorContainer container)
		{
			_container = container;
		}

		protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
		{
			if (controllerType == null) return null;
			return _container.Resolve(controllerType) as IController;
		}
	}
}